package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.IBaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lsj
 * @create 2021-08-04 21:16
 */
@RestController
@RequestMapping("/admin/product")
@Slf4j
public class BaseTrademarkController {


    @Autowired
    IBaseTrademarkService baseTrademarkService;


    /**
     * 分页查询所有品牌
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result<Page<BaseTrademark>> baseTrademarkPage(@PathVariable("page") Long page,
                                                         @PathVariable("limit") Long limit){


        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,limit);
        Page<BaseTrademark> page1 = baseTrademarkService.page(baseTrademarkPage);

        return Result.ok(page1);
    }

    /**
     * 保存品牌
     * @param baseTrademark
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result  baseTrademarkSave(@RequestBody  BaseTrademark baseTrademark){

        log.info("baseTrademark保存数据:{}",baseTrademark);
        boolean save = baseTrademarkService.save(baseTrademark);

        return Result.ok();
    }

    /**
     * 修改品牌
     * @param baseTrademark
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result  baseTrademarkUpdate(@RequestBody  BaseTrademark baseTrademark){

        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result baseTrademarkRemove(@PathVariable("id")  Long id){

        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 按照id获取品牌
     * @param id
     * @return
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result<BaseTrademark> baseTrademarkGet(@PathVariable("id")  Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);

        return Result.ok(baseTrademark);
    }

    @GetMapping("/baseTrademark/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList(){

        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}